Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete unused and broken LatLngBounds.pad() method. #1427

Merged
merged 1 commit into from
Feb 5, 2023

Conversation

ignatz
Copy link
Contributor

@ignatz ignatz commented Jan 2, 2023

The method fails to deal correctly with LatLng wrap arounds. A more correct version would probably look more like:

void pad(double bufferRatio) {
  final heightBuffer = (_sw!.latitude - _ne!.latitude).abs() * bufferRatio;
  final widthBuffer = (_sw!.longitude - _ne!.longitude).abs() * bufferRatio;

  final point1 = LatLng((90 + _sw!.latitude - heightBuffer) % 180 - 90,
      (180 + _sw!.longitude - widthBuffer) % 360 - 180);
  final point2 = LatLng((90 + _ne!.latitude + heightBuffer) % 180 - 90,
      (180 + _ne!.longitude + widthBuffer) % 360 - 180);

  final newBounds = LatLngBounds(point1, point2);
  _sw = newBounds.southWest;
  _ne = newBounds.northEast;
}

On a tangent, it probably should be a factory rather than a mutable method and the bufferRatio parameter is hard to use correctly. For example, bufferRatio = 0.5 would increase the bounds to 4 times its original size.

The method fails to deal correctly with LatLng wrap arounds. A more
correct version would probably look more like:

    void pad(double bufferRatio) {
      final heightBuffer = (_sw!.latitude - _ne!.latitude).abs() * bufferRatio;
      final widthBuffer = (_sw!.longitude - _ne!.longitude).abs() * bufferRatio;

      final point1 = LatLng((90 + _sw!.latitude - heightBuffer) % 180 - 90,
          (180 + _sw!.longitude - widthBuffer) % 360 - 180);
      final point2 = LatLng((90 + _ne!.latitude + heightBuffer) % 180 - 90,
          (180 + _ne!.longitude + widthBuffer) % 360 - 180);

      final newBounds = LatLngBounds(point1, point2);
      _sw = newBounds.southWest;
      _ne = newBounds.northEast;
    }

On a tangent, it probably should be a factory rather than a mutable
method and the `bufferRatio` parameter is hard to use correctly. For
example, bufferRatio = 0.5 would increase the bounds to 4 times its
original size.
@ignatz
Copy link
Contributor Author

ignatz commented Feb 4, 2023

Any thoughts on deleting already broken code?

@JaffaKetchup
Copy link
Member

Hey @ignatz, sorry for the massive delay. I'll take a look tommorrow.

@JaffaKetchup
Copy link
Member

Thanks for the contribution :)

@JaffaKetchup JaffaKetchup merged commit 26a3662 into fleaflet:master Feb 5, 2023
@S-ecki
Copy link

S-ecki commented Aug 22, 2023

Thanks for the contribution!
I am maintaining a codebase where .pad() was used and want to upgrade the dependency now. How would you go about changing the code using .pad()?

@ignatz
Copy link
Contributor Author

ignatz commented Aug 22, 2023

Naively, grab above version and provide it as a function or extension on latlngbounds

adamhb123 pushed a commit to adamhb123/flutter_map that referenced this pull request Sep 13, 2024
A similar method of the same name was removed in fleaflet#1427.

This method simply expands the LatLngBounds coordinates by
latitude and longitude constants.

Checks to ensure the adjustment remains "in-bounds" is performed,
similar to the extend and extendBounds methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants